﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.Runtime.InteropServices;


namespace HDF5
{

    using hid_t = System.Int32;
    using herr_t = System.Int32;
    using hsize_t = System.UInt64;
    using hssize_t = System.Int64;
    using hunsigned = System.UInt32;

    using hbool_t = System.UInt32;
    using htri_t = System.Int32;
    using ssize_t = System.Int64;

    using haddr_t = System.UInt64;

    using uint32_t = System.UInt32;
    using uint64_t = System.UInt64;

    using H5O_msg_crt_idx_t = System.UInt32;

    using size_t = System.UInt32;

    using off_t = System.Int32;

    using H5E_major_t = System.Int32;
    using H5E_minor_t = System.Int32;

    using time_t = System.Int64;
    using H5Z_filter_t = System.Int32;  


    #region enums
    public enum H5I_type_t {
    H5I_UNINIT		= (-2), /*uninitialized type			    */
    H5I_BADID		= (-1),	/*invalid Type				    */
    H5I_FILE		= 1,	/*type ID for File objects		    */
    H5I_GROUP,		        /*type ID for Group objects		    */
    H5I_DATATYPE,	        /*type ID for Datatype objects		    */
    H5I_DATASPACE,	        /*type ID for Dataspace objects		    */
    H5I_DATASET,	        /*type ID for Dataset objects		    */
    H5I_ATTR,		        /*type ID for Attribute objects		    */
    H5I_REFERENCE,	        /*type ID for Reference objects		    */
    H5I_VFL,			/*type ID for virtual file layer	    */
    H5I_GENPROP_CLS,            /*type ID for generic property list classes */
    H5I_GENPROP_LST,            /*type ID for generic property lists        */
    H5I_ERROR_CLASS,            /*type ID for error classes		    */
    H5I_ERROR_MSG,              /*type ID for error messages		    */
    H5I_ERROR_STACK,            /*type ID for error stacks		    */
    H5I_NTYPES		        /*number of library types, MUST BE LAST!    */
    }
    #endregion enums

    #region delegates
    /*
     * Function for freeing objects. This function will be called with an object
     * ID type number and a pointer to the object. The function should free the
     * object and return non-negative to indicate that the object
     * can be removed from the ID type. If the function returns negative
     * (failure) then the object will remain in the ID type.
     */
    public delegate herr_t H5I_free_t(IntPtr idobjects);

    /* Type of the function to compare objects & keys */
    public delegate int H5I_search_func_t(IntPtr obj, hid_t id, IntPtr key);

    #endregion delegates

    public static class H5I
    {
        public static hid_t H5I_INVALID_HID = -1;

        #region Identifier Interface
        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Iget_file_id( hid_t obj_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern ssize_t H5Iget_name( hid_t obj_id, StringBuilder name, size_t size )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern H5I_type_t H5Iget_type( hid_t obj_id );

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern IntPtr H5Iobject_verify( hid_t id, H5I_type_t id_type )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern IntPtr H5Iremove_verify( hid_t id, H5I_type_t id_type ) ;

        //[DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        //public static extern void *H5Isearch( H5I_type_t type, H5I_search_func_t func, void *key ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern htri_t H5Iis_valid( hid_t obj_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Iget_ref( hid_t obj_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Iinc_ref( hid_t obj_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Idec_ref( hid_t obj_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Iregister( H5I_type_t type, IntPtr ptrObject ) ;

        //[DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        //public static extern H5I_type_t H5Iregister_type( size_t hash_size, unsigned reserved, H5I_free_t free_func ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Idestroy_type( H5I_type_t type ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern htri_t H5Itype_exists( H5I_type_t type ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Iget_type_ref( H5I_type_t type ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Idec_type_ref( H5I_type_t type ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern int H5Iinc_type_ref( H5I_type_t type ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Iclear_type( H5I_type_t type, hbool_t force ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Inmembers( H5I_type_t type, out hsize_t num_members ) ;

        #endregion Identifier Interface

    }
}
